package com.jt.demos;

import redis.clients.jedis.Jedis;

/**
 * 分布式ID逐步递增策略
 * 多张表基于方法中生成的id作为主键id值
 * 分布式环境下不会采用数据库表中自带的自增策略: auto-increment
 */
public class IdGeneratorDemo01 {

    public static Long getId(){
        Jedis jedis  = new Jedis("192.168.126.129",6379);
        Long id = jedis.incr("id");
        jedis.close();
        return id;
    }

    public static void main(String[] args) {
        for (int i=0;i<=10;i++){
            new Thread(){
                @Override
                public void run() {
                    String threadName = Thread.currentThread().getName();
                    System.out.println(threadName+"->"+IdGeneratorDemo01.getId());
                }
            }.start();
            //System.out.println(getId());
        }
    }
}
